package com.shujia.mr.youhua;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapred.MapTask;
import org.apache.hadoop.mapred.ReduceTask;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

/*
    给一个10000条温度数据，求出每年2月份的最高温度
 */
public class WeatherDemo {
    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
//        conf.set("mapreduce.input.fileinputformat.split.minsize","256");
//        conf.set("mapreduce.input.fileinputformat.split.maxsize","64");
//        conf.set("mapreduce.map.sort.spill.percent","0.7F");
//        conf.set("mapreduce.task.io.sort.mb","200");
        Job job = Job.getInstance(conf);
        job.setJobName("27期 求每年2月份的最高温度案例");
        job.setJarByClass(WeatherDemo.class);

//        job.setNumReduceTasks(2);

        job.setMapperClass(WeatherMapper.class);
        job.setReducerClass(WeatherReducer.class);
        //如果预聚合的逻辑与reduce的逻辑一样的话，这里只需要加一行代码即可实现预聚合
//        job.setCombinerClass(WeatherReducer.class);
        job.setNumReduceTasks(0);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(LongWritable.class);

//        job.setOutputKeyClass(Text.class);
//        job.setOutputValueClass(LongWritable.class);

        FileInputFormat.addInputPath(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));

        job.waitForCompletion(true);

//        MapTask
//        ReduceTask
    }
}
